package com.zyf.chapter01.practice.v2;


import com.zyf.chapter01.principle.practice.MetricsCollector;
import com.zyf.chapter01.principle.practice.MetricsStorage;
import com.zyf.chapter01.principle.practice.RedisMetricsStorage;
import com.zyf.chapter01.principle.practice.RequestInfo;

/**
 * 使用
 *
 * @author yifeng
 */
public class PerfCounterTest {
    public static void main(String[] args) {
        MetricsStorage storage = new RedisMetricsStorage();
        Aggregator aggregator = new Aggregator();

        // 定时触发统计并将结果显示到终端
        ConsoleViewer consoleViewer = new ConsoleViewer();
        ConsoleReporter consoleReporter =
                new ConsoleReporter(storage, aggregator, consoleViewer);
        consoleReporter.startRepeatedReport(60, 60);

        // 定时触发统计结果并将结果输出到邮件
        EmailViewer emailViewer = new EmailViewer();
        EmailReporter emailReporter = new EmailReporter(storage, aggregator, emailViewer);
        emailReporter.startDailyReport();

        // 收集接口访问数据
        MetricsCollector collector = new MetricsCollector(storage);
        collector.recordRequest(new RequestInfo("register", 123, 10244));
        collector.recordRequest(new RequestInfo("register", 223, 10244));
        collector.recordRequest(new RequestInfo("register", 323, 10244));
        collector.recordRequest(new RequestInfo("login", 23, 10244));
        collector.recordRequest(new RequestInfo("login", 2123, 10244));

        try {
            Thread.sleep(100000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
